package com.wellsoft.mobileoa.utils;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.TextView;

import com.wellsoft.mobileoa.R;
import com.wellsoft.mobileoa.wsmodel.WSOA_PageFieldOption;
import com.wmobile.utils.PopListDialogAdapter;

public class SelectOpitonDataAdapter extends
		PopListDialogAdapter<String> {

	public SelectOpitonDataAdapter(BaseActivity baseActivity,
			List<String> dataList, List<Integer> selectedIndex,
			boolean isMultiSelect) {
		this.baseActivity = baseActivity;
		this.dataList = dataList;
		this.selectedIndex = selectedIndex;
		this.isMultiSelect = isMultiSelect;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (isMultiSelect) {
			convertView = LayoutInflater.from(baseActivity).inflate(
					R.layout.poplistdialogcheckboxitem, null);

			TextView itemTv = (TextView) convertView.findViewById(R.id.itemtv);
			itemTv.setText(dataList.get(position));

			TextView item1Tv = (TextView) convertView
					.findViewById(R.id.item1tv);
			item1Tv.setVisibility(View.GONE);

			CheckBox itemRb = (CheckBox) convertView.findViewById(R.id.itemcb);
			itemRb.setTag(position);
			if (selectedIndex.contains(Integer.valueOf(position))) {
				itemRb.setChecked(true);
			}
		} else {
			convertView = LayoutInflater.from(baseActivity).inflate(
					R.layout.poplistdialogradioitem, null);

			TextView itemTv = (TextView) convertView.findViewById(R.id.itemtv);
			itemTv.setText(dataList.get(position));

			TextView item1Tv = (TextView) convertView
					.findViewById(R.id.item1tv);
			item1Tv.setVisibility(View.GONE);

			RadioButton itemRb = (RadioButton) convertView
					.findViewById(R.id.itemrb);
			itemRb.setOnClickListener(radioButtonClickListener);
			itemRb.setTag(position);
			if (selectedIndex.contains(Integer.valueOf(position))) {
				itemRb.setChecked(true);
			}
		}

		return convertView;
	}
}
